/*
 * @lc app=leetcode.cn id=1103 lang=typescript
 *
 * [1103] 分糖果 II
 */

// @lc code=start
function distributeCandies(candies: number, num_people: number): number[] {
    const list = Array(num_people).fill(0);
    let round = 0;
    let now = 1;
    while (candies > 0) {
        const cost = now + round * num_people;
        if (candies >= cost) {
            candies -= cost;
            list[now - 1] += cost;
        } else {
            list[now - 1] += candies;
            break;
        }
        if (now + 1 > num_people) {
            round++;
            now = 1;
        } else {
            now++;
        }
    }
    return list;
}
// @lc code=end
